package com.guodi.model.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guodi.model.constant.CommonConst;
import com.guodi.model.entity.MdlFactor;
import com.guodi.model.mapper.MdlFactorMapper;
import com.guodi.model.service.IMdlFactorService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @描述：模型因子表 服务类
 * @作者: 代鹏刚
 * @日期: 2020-06-17
 */
@Service
public class MdlFactorServiceImpl extends ServiceImpl<MdlFactorMapper, MdlFactor> implements IMdlFactorService {

    @Override
    public IPage<MdlFactor> listByEntity(Page page, MdlFactor mdlFactor, CommonConst commonConst) {
        LambdaQueryWrapper<MdlFactor> queryWrapper = (new QueryWrapper()).lambda();
        if(StringUtils.isNotBlank(commonConst.getKeyWord())){
            queryWrapper.like(MdlFactor::getName,commonConst.getKeyWord());
        }
        if(StringUtils.isNotBlank(commonConst.getSortType())){
            if(commonConst.getSortType().equals("1")){
                if(commonConst.getSortMethod().equals("1")){
                    queryWrapper.orderByDesc(MdlFactor::getCreateTime);
                }else {
                    queryWrapper.orderByAsc(MdlFactor::getCreateTime);
                }
            }else {
                if(commonConst.getSortMethod().equals("1")){
                    queryWrapper.orderByDesc(MdlFactor::getName);
                }else {
                    queryWrapper.orderByAsc(MdlFactor::getName);
                }
            }
        }
        return this.page(page, queryWrapper);
    }
}